package org.mspring.platform.utils;

import java.io.IOException;
import java.util.Properties;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 *
 * @since 2014-04-04 17:30:05
 * @author Gao Youbo
 */
public class PropertyConfigurer extends PropertyPlaceholderConfigurer {

    private Properties properties;

    public String getString(String key) {
        return properties.getProperty(key);
    }

    public String getString(String key, String defaultValue) {
        return properties.getProperty(key, defaultValue);
    }

    public Integer getInteger(String key) {
        String value = getString(key);
        if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
            return null;
        }
        return Integer.parseInt(value.trim());
    }

    public Integer getInteger(String key, int defaultValue) {
        String value = getString(key);
        if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
            return defaultValue;
        }
        return Integer.parseInt(value.trim());
    }

    @Override
    protected Properties mergeProperties() throws IOException {
        properties = super.mergeProperties();
        return properties;
    }

}
